//
//  CZQTabBarButton.m
//  weibo
//
//  Created by Apple on 15-1-30.
//  Copyright (c) 2015年 itcast. All rights reserved.
//

#import "CZQTabBarButton.h"

@implementation CZQTabBarButton
- (id)initWithCoder:(NSCoder *)aDecoder{
    self = [super initWithCoder:aDecoder];
    
    if (self) {
        [self setup];
    }
    return self;
}
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];

    }
    return self;
}
/**
 *  初始化
 */
- (void)setup{
    self.imageView.contentMode = UIViewContentModeCenter;
    //文字居中
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.font = [UIFont systemFontOfSize:15.0];
    //设置文字的颜色
    [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self setTitleColor:[UIColor orangeColor] forState:UIControlStateSelected];
}


- (CGRect)imageRectForContentRect:(CGRect)contentRect{
  
    CGFloat imageW = contentRect.size.width;
    CGFloat imageH = contentRect.size.height*0.6;
    CGFloat imageX = 0;
    CGFloat imageY = 0;
    
    return CGRectMake(imageX, imageY, imageW, imageH);
 
}
- (CGRect)titleRectForContentRect:(CGRect)contentRect{
    CGFloat titleW = contentRect.size.width;
    CGFloat titleH = contentRect.size.height - contentRect.size.height * 0.6;
    CGFloat titleX = 0;
    CGFloat titleY = contentRect.size.height * 0.6;
    
    return CGRectMake(titleX, titleY, titleW, titleH);
}
- (void)setItem:(UITabBarItem *)item{

    _item = item;
    [self setTitle:item.title forState:UIControlStateNormal];
    [self setImage:item.image forState:UIControlStateNormal];
    [self setImage:item.selectedImage forState:UIControlStateSelected];
    

}
@end
